<?php

namespace app\merch\controller;

use app\merch\controller\Main;
use think\Controller;
use think\Db;

class Recharge extends Main {

    public function index() {

        $_GPC = input();
        $page = max(intval($_GPC['page']), 1);
        $limit = max(intval($_GPC['limit']), 10);

        $params = array(['r.status' => 1]);
        if ($this->merchinfo['isagent'] == 0) {
            $params['r.member_id'] = $this->merchinfo['id'];
        } else {
            if ($this->sysset['agent_level'][$this->merchinfo['agent_level']]['type'] == 0) {
                $params['r.agent_id'] = $this->merchinfo['id'];
            }
            if ($this->sysset['agent_level'][$this->merchinfo['agent_level']]['type'] == 1) {
                $params['r.province'] = $this->merchinfo['province'];
                $params['r.city'] = $this->merchinfo['city'];
                $params['r.district'] = $this->merchinfo['area'];
                $params['r.agent_id'] = $this->merchinfo['id'];
            }
            if ($this->sysset['agent_level'][$this->merchinfo['agent_level']]['type'] == 2) {
                $params['r.province'] = $this->merchinfo['province'];
                $params['r.city'] = $this->merchinfo['city'];
                $params['r.agent_id'] = $this->merchinfo['id'];
            }
            if ($this->sysset['agent_level'][$this->merchinfo['agent_level']]['type'] == 3) {
                $params['r.province'] = $this->merchinfo['province'];
                $params['r.agent_id'] = $this->merchinfo['id'];
            }
        }
        $db = Db::name('recharge_log')->alias('r')->join('member m', 'r.member_id=m.id')->where($params);
        $count = $db->count();
        $data = $db->order('r.createtime DESC')->limit(($page - 1) * $limit, $limit)->select();
        jsonp($data, $count);
    }

}
